<%@ page import="com.wuming.caiwu.security.SecurityHander" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>管理学员信息</title>
    <link rel="stylesheet" href="${allServerPath}static/layui/layui/css/layui.css">
    <link rel="stylesheet" href="${allServerPath}static/layui/css/formSelects-v4.css">
    <style>
        .query-condition {
            margin-top: 15px;
        }
    </style>
</head>
<body style="background-color: #f0f2f5;">
<div style="padding: 15px;margin: 15px;background-color: #fff;">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>学员信息查询</legend>
    </fieldset>
    <form id="queryForm" class="layui-form" action="">
        <div class="" style="margin-top: 15px;">
            <div class="layui-row query-condition">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">姓名</label>

                        <div class="layui-input-inline">
                            <input type="text" id="studentName" name="studentName" placeholder="请输入学员姓名"
                                   lay-verify="name"
                                   autocomplete="off"
                                   class="layui-input" value="${studentName}">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">手机号</label>

                        <div class="layui-input-inline">
                            <input type="text" name="mobile" placeholder="请输入手机号" id="mobile" lay-verify="phone"
                                   autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">准驾车型</label>

                        <div class="layui-input-inline">
                            <select id="carType" name="carType" lay-filter="teacher" lay-search>
                                <option value=""></option>
                                <option value="C1">C1</option>
                                <option value="C2">C2</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">身份证</label>
                        <div class="layui-input-block" style="width: 838px">
                            <textarea id="certNo" name="certNo" placeholder="请输入内容,使用回车分割,每行最多一个身份证号" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>

            </div>
            <div class="layui-row query-condition">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">开始时间</label>

                        <div class="layui-input-inline">
                            <input type="text" name="startTime" id="startTime" placeholder=""
                                   autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">结束时间</label>

                        <div class="layui-input-inline">
                            <input type="text" name="endTime" id="endTime" placeholder=""
                                   autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>

    <div class="layui-row query-condition" style="padding: 9px 15px;margin-bottom: 20px;">
        <button name="btnQuery" class="layui-btn layui-btn-normal" data-type="reload">查询搜索</button>
    </div>

    <table class="layui-hide" id="studentsInfo" lay-filter="demo" lay-data="{height: 'full-200'}">
    </table>
</div>


<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="view">详细信息</a>
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail">编辑</a>
    <a class="layui-btn layui-btn-xs" lay-event="del">删除</a>
</script>

<script src="${allServerPath}static/layui/layui/layui.js"></script>
<script>
    layui.config({
        base: '${allServerPath}static/layui/build/js/'
    }).extend({
        formSelects: 'formSelects-v4.min'
    }).use(['table', 'jquery', 'navbar', 'laydate', 'form', 'element', 'formSelects'], function () {
        var table = layui.table,
            $ = layui.jquery,
            form = layui.form,
            laydate = layui.laydate,
            formSelects = layui.formSelects,
            element = layui.element;

        laydate.render({
            elem: '#startTime',
            type: 'datetime'
        });

        laydate.render({
            elem: '#endTime',
            type: 'datetime'
        });

        var studentName = $("#studentName").val();
        table.render({ //其它参数在此省略
            elem: '#studentsInfo'
//            , height: 500
            , url: '${allServerPath}web/student/list.htmls?t=' + Date.parse(new Date())
            , cols: [[ //表头
                {type: 'checkbox'}
                , {field: 'id', align: 'center', title: 'ID', width: 80}
                , {field: 'studentName', title: '用户名', align: 'center', width: 100}
                , {field: 'mobile', title: '手机号', align: 'center', width: 140}
                , {field: 'certNo', title: '证件号', align: 'center', width: 180}
                , {field: 'admitCarType', title: '准驾车型', align: 'center', width: 180}
                , {field: 'businessType', title: '申请类型', align: 'center', width: 180}
                , {field: 'createDatetime', title: '录入时间', align: 'center', width: 180}
                , {field: 'signDate', title: '报名时间', align: 'center', width: 180}
                , {fixed: 'right', title: '操作', width: 200, align: 'center', toolbar: '#barDemo'}
            ]],
            id: 'studentContent',
            where: {
                "memberId": '<%=SecurityHander.getCurrentUserId()%>',
                "studentName": encodeURI(studentName)
            }, //如果无需传递额外参数，可不加该参数
            method: 'get', //如果无需自定义HTTP类型，可不加该参数
            page: true,
            limits: [10, 20, 30, 50, 100, 200],
            limit: 10,
            request: {
                pageName: 'pageIndex', //页码的参数名称，默认：page
                limitName: 'pageSize'
            }, //如果无需自定义请求参数，可不加该参数
            response: {
                statusName: 'code' //数据状态的字段名称，默认：code
                , statusCode: 200 //成功的状态码，默认：0
                , msgName: 'message' //状态信息的字段名称，默认：msg
                , countName: 'total' //数据总数的字段名称，默认：count
                , dataName: 'data' //数据列表的字段名称，默认：data
            }, //如果无需自定义数据响应名称，可不加该参数
            done: function (res, curr, count) {
                //如果是异步请求数据方式，res即为你接口返回的信息。
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                console.log(res);

                //得到当前页码
                console.log(curr);

                //得到数据总量
                console.log(count);
            },
            text: {
                none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
            }
        });


        table.on('tool(demo)', function (obj) {
            var data = obj.data;
            if (obj.event === 'view') {
                layer.open({
                    type: 2,
                    title: '详细信息',
                    maxmin: true,
                    shadeClose: true, //点击遮罩关闭层
                    area: ['1000px', '580px'],
                    content: '${allServerPath}web/student/view/' + data.id + '.htmls'
                });
            }
            else if (obj.event === 'detail') {
                //layer.msg('ID：' + data.id + ' 的查看操作')
                parent.window.tab.tabAdd({
                    'id': 'detail_' + data.id,
                    'title': '查看学员信息',
                    'icon': '',
                    'url': '${allServerPath}web/student/editStudent/' + data.id + '.htmls'
                });
            } else if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    $.ajax({
                            url: '${allServerPath}web/student/delete/' + data.id + ".htmls",
                            method: 'get',
                            dataType: 'json',
                            success: function (result) {
                                if (result.success) {
                                    obj.del();
                                    layer.close(index);
                                }
                            },
                            error: function () {
                                layer.msg('删除失败,请稍后重试.');
                            }
                        }
                    );
                });
            }
        });

        $('button[name="btnQuery"]').on('click', function () {
//            var type = $(this).data('type');
//            active[type] ? active[type].call(this) : '';
            var sName = $('#studentName');

            var cNo = $("#certNo");
            var ref = JSON.stringify(formSelects.value('select1', 'valStr'));
            ref=ref.substr(0,ref.length-1);
            ref=ref.substr(1,ref.length-1);

            table.reload('studentContent', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: {
                    "studentName": encodeURI(sName.val()),
                    "certNo": cNo.val(),
                    "signAddrId": $('#signAddrId').val(),
                    "mobile": $('#mobile').val(),
                    "mealId": $('#mealId').val(),
                    "referrer": ref,
                    "timeType": $('#timeType').val(),
                    "teacherCertNo": $('#teacher').val(),
                    "facultyId": $('#facultyId').val(),
                    "cName": $('#cName').val(),
                    "startTime": $('#startTime').val(),
                    "endTime": $('#endTime').val(),
                    "admitCarType": $('#carType').val()
                }
            });
        });

        $('button[name="btnExport"]').on('click', function () {
            var par = new Object();
            par["memberId"] = '<%=SecurityHander.getCurrentUserId()%>';
            $.post('${allServerPath}/web/student/exportStudent.htmls', par,
                function (data) {
                    if (data.success) {
                        layer.msg('导出成功.');
                        FileUtil.downFile("${allServerPath}/web/student/downLoadTempFile.htmls", data.data);
                    } else {
                        layer.msg('导出失败,请稍后重试.');
                    }
                }, "json");
        });

        active = {
            getCheckData: function () { //获取选中数据
                var  checkStatus = table.checkStatus('studentContent')
                    , data = checkStatus.data;
                var studentIds = "";
                if (data.length > 0) {
                    for (var i = 0; i < data.length; i++) {
                        if (studentIds == "") {
                            studentIds = data[i].studentName + "-" + data[i].mobile;
                        } else {
                            studentIds = studentIds + "," + data[i].studentName + "-" + data[i].mobile;
                        }
                    }
                }
                return studentIds;
            }
        };

        $('button[name="btnNotice"]').on('click', function () {
            var studentIds = active.getCheckData();
            if (studentIds == "") {
                layer.msg("请选择学员再进行短信通知");
                return false;
            }
            parent.window.tab.tabAdd({
                'id': 'sms_student',
                'title': '短信通知',
                'icon': '',
                'url': "${allServerPath}web/message/mesgNotice/<%=SecurityHander.getCurrentUserId()%>/" + studentIds + ".htmls"
            })
        });

        $('button[name="btnImport"]').on('click', function () {

            parent.window.tab.tabAdd({
                'id': 'import_student',
                'title': '导入学员信息',
                'icon': '',
                'url': '${allServerPath}web/student/toImportStudent.htmls'
            });

            //console.log(parent.window.tab);
//            element.tabAdd("kitTab");
//            element.render("tab","kitTab");
        });

        /**
         * 下载文件链接
         */
        var FileUtil = {
            downFile: function (url, data) {
                if (url && data) {
                    var inputs = '';
                    for (var p in data) {
                        inputs += '<input type="hidden" name="' + p + '" value="' + data[p]
                            + '" />';
                    }
                    $('<form action="' + url + '" method="post">' + inputs + '</form>')
                        .appendTo('body').submit().remove();
                }
            }
        }

    });

</script>
</body>
</html>
